# -*- coding:utf-8 -*-
# author:qiong   time:2021/9/17
import allure
from selenium.webdriver.common.by import By
from mkzAPP_test.base.baseApp import basePageElement, baseHandle

# 登录页面对象

class loginElement(basePageElement):
    def __init__(self):
        super().__init__()
        # 获取切换账号密码登录按钮
        self.toAccount = By.ID,"com.xmtj.mkz:id/tv_account_login"
        # 获取账号输入框
        self.username = By.ID,"com.xmtj.mkz:id/et_phone"
        # 获取密码输入框
        self.password = By.ID,"com.xmtj.mkz:id/et_password"
        # 获取勾选同意协议复选框
        self.agreebox = By.ID,"com.xmtj.mkz:id/agree_chechbox"
        # 获取登录按钮
        self.loginbtn = By.ID,"com.xmtj.mkz:id/tv_login"

    def find_toAccount(self):
        return self.wait_getelement(self.toAccount)

    def find_username(self):
        return self.wait_getelement(self.username)

    def find_password(self):
        return self.wait_getelement(self.password)

    def find_agreebox(self):
        return self.wait_getelement(self.agreebox)

    def find_loginbtn(self):
        return self.wait_getelement(self.loginbtn)

# 操作层
class loginHandle(baseHandle):
    def __init__(self):
        self.login_element = loginElement()

    # 切换到账号密码输入面
    def clikc_to_account(self):
        self.login_element.find_toAccount().click()

    # 输入账号
    @allure.step(title="输入账号")
    def input_username(self,username):
        self.input_text(self.login_element.find_username(),username)

    # 输入密码
    @allure.step(title="输入密码")
    def inpu_password(self,password):
        self.input_text(self.login_element.find_password(),password)

    # 勾选同意复选框
    def click_agreebox(self):
        self.login_element.find_agreebox().click()

    # 点击登录按钮
    def click_loginbtn(self):
        self.login_element.find_loginbtn().click()


# 业务层
class loginProxy:
    def __init__(self):
        self.login_handle = loginHandle()

    # 切换登录方式,勾选同意协议
    def go_to_Accoun(self):
        self.login_handle.clikc_to_account()
        self.login_handle.click_agreebox()

    # 实现登录
    def app_login(self,username,password):
        self.login_handle.input_username(username)
        self.login_handle.inpu_password(password)
        self.login_handle.click_loginbtn()